package cn.virens.web.components.beetl.tag.menus;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.StrUtil;

public class Menu implements Serializable {
	private static final long serialVersionUID = 6795095378505779874L;
	private final Menu parent;

	private String icon;
	private String name;
	private String linkurl;
	private String identity;
	private List<Menu> childrens;

	public static Menu parent(Menu parent) {
		return new Menu(parent);
	}

	private Menu(Menu parent) {
		this.parent = parent;
	}

	public Menu getParent() {
		return parent;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLinkurl() {
		return linkurl;
	}

	public void setLinkurl(String linkurl) {
		this.linkurl = linkurl;
	}

	public String getIdentity() {
		return identity;
	}

	public void setIdentity(String identity) {
		this.identity = identity;
	}

	public List<Menu> getChildrens() {
		return childrens;
	}

	public void setChildrens(List<Menu> childrens) {
		this.childrens = childrens;
	}

	public void addChildrens(Menu children) {
		if (childrens == null) {
			this.childrens = new ArrayList<>();
		}

		this.childrens.add(children);
	}

	public boolean getHasChildrens() {
		return childrens != null && !childrens.isEmpty();
	}

	public String active(String identity) {
		boolean isActive = StrUtil.startWith(identity, this.identity);
		if (childrens != null && !childrens.isEmpty()) {
			return isActive ? "layui-nav-itemed" : "none";
		} else {
			return isActive ? "layui-this" : "none";
		}
	}
}
